package org.urchr.beorganized.api.impl.user;

import org.urchr.beorganized.api.base.PrivateBaseAPIServlet;
import org.urchr.beorganized.dao.NotesDAO;
import org.urchr.beorganized.dao.UsersDAO;
import org.urchr.beorganized.dao.XMLDocumentBuilder;
import org.urchr.beorganized.dao.errors.DBErrorException;
import org.urchr.beorganized.dao.errors.GeneralException;
import org.urchr.beorganized.dao.tables.User;

public class UpdateUser extends PrivateBaseAPIServlet {

	@Override
	protected void doProcessPrivate() throws GeneralException {
		// TODO Auto-generated method stub
		if(xmlObject!=null){
			User user = UsersDAO.getUser(userID);
			user.setName(xmlObject.getAttribute("name"));
			user.setEmail(xmlObject.getAttribute("email"));
			user.setDateFormat(xmlObject.getAttribute("dateFormat"));
			user.setTimeFormat(xmlObject.getAttribute("timeFormat"));			
			user.setTimeZone(xmlObject.getAttribute("timeZone"));			
//			user.setMinuteOffset(NotesDAO.safeInt(xmlObject.getAttribute("minuteOffset"), 0));
			UsersDAO.updateUser(userID, user);
			XMLDocumentBuilder doc = new XMLDocumentBuilder();
			UsersDAO.userToNode(doc, doc.getRootElement("user"), UsersDAO.getUser(userID));
			sendNode(doc.getRootElement());
			return;
		}
		throw new DBErrorException();
	}

}
